#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys, traceback, Ice
Ice.loadSlice('Ripper.ice', ['-I' '/usr/share/slice'])
import Ripper

class Mp3EncoderI (Ripper.Mp3Encoder):
    def encode (self, leftSamples, rightSamples, current):
        print 'Encoding...'
        return None

    def flush (self, current):
        print 'Flushing...'
        return None
    
class Mp3EncoderFactoryI (Ripper.Mp3EncoderFactory):
    def createEncoder (self, current):
        prx = current.adapter.addWithUUID(Mp3EncoderI())
        adapterId = current.adapter.getCommunicator().getProperties().getProperty(current.adapter.getName() + ".AdapterId")
        return Ripper.Mp3EncoderPrx.uncheckedCast(prx.ice_adapterId(adapterId))
        # BUG ICEPy
        # prx = current.adapter.addWithUUID(Mp3EncoderI())
        # return Ripper.Mp3EncoderPrx.uncheckedCast(current.adapter.createIndirectProxy(prx.ice_getIdentity()))
        # FIN BUG
                                        
class Server (Ice.Application):
    def run (self, argv):
        self.shutdownOnInterrupt()
        adapter = self.communicator().createObjectAdapter('EncoderAdapter')
        adapter.add(Mp3EncoderFactoryI(), Ice.stringToIdentity('EncoderFactory'))
        adapter.activate()
        self.communicator().waitForShutdown()
        return 0

Server().main(sys.argv)
